package cn.elead.it.template.sql;

import org.apache.ibatis.jdbc.SQL;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;

import cn.elead.it.template.model.vo.Demo;
import lombok.NoArgsConstructor;

@NoArgsConstructor
public class DemoSql {


	public String findCDemos(Demo demo) {
		return new SQL() {
			{
				SELECT("course.*, image.IMAGE_URL coursePicUrl");
				SELECT("(select count(1) from e_course_chapter chapter where chapter.parent_id!=0 and chapter.course_id = course.id) chapterCount");
				FROM("e_course_info course");
				LEFT_OUTER_JOIN("e_media_image image on course.COURSE_PIC_ID = image.id");
				if (ObjectUtils.isNotEmpty(demo.getName())) {
					WHERE("course.course_category_id IN (select c.id from e_cource_category c where c.id = ${cource.courseCategoryId} union select c.id from e_cource_category c where c.parent_id = ${cource.courseCategoryId})");
				}
				ORDER_BY("course.created_time desc");
			}
		}.toString();
	}
	
}
